<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.js"></script>
</head>
<body>
    

    <div id="app">

        <!-- v-model指令多用在表单元素  input\select\textarea -->

        <label>
            <input type="checkbox" name="checkAll" v-model="checkAll" @change="changes"> 全选
        </label>

        <hr>

        <label v-for="(item, index) in hobbyList" :key="index">
            <input type="checkbox" name="item" :value="item" v-model="selected"> {{item}}
        </label>

        <hr>

        {{ selected }} {{checkAll}}

        <hr>


        <span v-pre>
            {{ this is txt... }}
        </span>


    </div>

    <script>

        new Vue({
            el: '#app',
            data: {
                checkAll: false,
                selected: [],
                hobbyList: [
                    '吃饭',
                    '睡觉',
                    '打豆豆'
                ]
            },
            methods: {
                changes() {
                    // this.checkAll如果为true，表示全选，否则反之.
                    // console.log(this.checkAll);
                    if (this.checkAll) {
                        this.selected = this.hobbyList;
                    }
                }
            }
        })

    </script>

</body>
</html>